String.prototype.trim = function () {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
};

Array.prototype.sortByStrField = function (field) {
	return this.sort(function(a, b){
			var strA = a[field].toLowerCase();
			var strB = b[field].toLowerCase();
			if (strA < strB) return -1;
			if (strA > strB) return 1;
 			return 0;
	});
};

Array.prototype.containInField = function (field, v) {
	var b = false;
	this.each(function(val){
		if(val[field] == v) {
			b = true;
			throw $break;
		}
	});
	return b;
};

Array.prototype.getFieldValues = function (field) {
	var a = [];
	this.each(function(val){
		a.push(val[field]);
	});
	return a.uniq();
};

Date.prototype.format = function (formatStr) {
	var yyyy = String(this.getFullYear());
	var MM = this.getMonth()<9 ? "0" + (this.getMonth()+1) : this.getMonth()+1;
	var dd = this.getDate()<10 ? "0" + this.getDate() : this.getDate();
	return formatStr.replace("yyyy", yyyy).replace("MM", MM).replace("dd", dd);
};
